package com.michael.ims.admin.config;

import com.querydsl.sql.MySQLTemplates;
import com.querydsl.sql.SQLQueryFactory;
import com.querydsl.sql.SQLTemplates;
import com.querydsl.sql.spring.SpringConnectionProvider;
import com.querydsl.sql.spring.SpringExceptionTranslator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.inject.Provider;
import javax.sql.DataSource;

@Configuration
public class QeuryDslConfig {
    @Autowired
    private DataSource dataSource;

    @Bean
    public SQLQueryFactory sqlQueryFactory() {
        SQLTemplates mySQLTemplates = MySQLTemplates.builder().build();
        com.querydsl.sql.Configuration configuration = new com.querydsl.sql.Configuration(mySQLTemplates);
        configuration.setExceptionTranslator(new SpringExceptionTranslator());
        Provider provider = new SpringConnectionProvider(dataSource);
        SQLQueryFactory queryFactory = new SQLQueryFactory(configuration, provider);
        return queryFactory;
    }

}
